home *** CD-ROM | disk | FTP | other *** search
/ Meeting Pearls 2 / Meeting Pearls Vol. II (1995)(GTI - Schatztruhe)[!].iso / Pearls / comm / Envoy / Conf / tk_svc.asm < prev    next >
Assembly Source File  |  1994-04-15  |  9KB  |  339 lines

  1. ;---------------------------------------------------------------------------
  2. ; Conference Server/Service written by Jeffrey A. Litz
  3. ;
  4. ; litz@cs.uwp.edu  -or-  Jeff_Litz@EDTNG.Kenosha.WI.US
  5. ;
  6. ; Copyright ©1994 JL Productions.
  7. ;---------------------------------------------------------------------------
  8.  
  9.         OPTIMON
  10.  
  11. ;---------------------------------------------------------------------------
  12.  
  13.         NOLIST
  14.  
  15.         INCDIR "include:"
  16.  
  17.         INCLUDE "exec/types.i"
  18.         INCLUDE "exec/libraries.i"
  19.         INCLUDE "exec/lists.i"
  20.         INCLUDE "exec/alerts.i"
  21.         INCLUDE "exec/initializers.i"
  22.         INCLUDE "exec/resident.i"
  23.         INCLUDE "libraries/dos.i"
  24.  
  25.         INCLUDE "tk_rev.i"
  26.         INCLUDE "tkbase.i"
  27.  
  28.         LIST
  29.  
  30. ;---------------------------------------------------------------------------
  31.  
  32.         XREF    _StartService
  33.         XREF    _Server
  34.         XREF    _GetServiceAttrsA
  35.         XREF    ENDCODE
  36.         XREF    _KPrintF
  37.  
  38. ;---------------------------------------------------------------------------
  39.  
  40.         XDEF    LibInit
  41.         XDEF    LibOpen
  42.         XDEF    LibClose
  43.         XDEF    LibExpunge
  44.         XDEF    LibReserved
  45.         XDEF    _TKSPassword
  46.         XDEF    _TKSSignalMask
  47.         XDEF    _TKSUser
  48.         XDEF    _TKSEntityName
  49.         XDEF    _TKSSMProc
  50.         XDEF    _TKSServer
  51.         XDEF    _TKSError
  52.  
  53.         XDEF    __sprintf
  54.         
  55. ;---------------------------------------------------------------------------
  56.  
  57. ; First executable location, must return an error to the caller
  58. Start:
  59.         moveq   #-1,d0
  60.         rts
  61.  
  62. ;-----------------------------------------------------------------------
  63.  
  64. ROMTAG:
  65.         DC.W    RTC_MATCHWORD           ; UWORD RT_MATCHWORD
  66.         DC.L    ROMTAG                  ; APTR  RT_MATCHTAG
  67.         DC.L    ENDCODE                 ; APTR  RT_ENDSKIP
  68.         DC.B    RTF_AUTOINIT            ; UBYTE RT_FLAGS
  69.         DC.B    VERSION                 ; UBYTE RT_VERSION
  70.         DC.B    NT_LIBRARY              ; UBYTE RT_TYPE
  71.         DC.B    0                       ; BYTE  RT_PRI
  72.         DC.L    LibName                 ; APTR  RT_NAME
  73.         DC.L    LibId                   ; APTR  RT_IDSTRING
  74.         DC.L    LibInitTable            ; APTR  RT_INIT
  75.  
  76. LibName DC.B 'conf.service',0
  77. LibId   VERSTAG
  78.  
  79.         CNOP    0,4
  80.  
  81. LibInitTable:
  82.         DC.L    TKSSvc_SIZEOF
  83.         DC.L    LibFuncTable
  84.         DC.L    LibDataTable
  85.         DC.L    LibInit
  86.  
  87. V_DEF   MACRO
  88.         DC.L    \1
  89.         ENDM
  90.  
  91. LibFuncTable:
  92.         V_DEF   LibOpen
  93.         V_DEF   LibClose
  94.         V_DEF   LibExpunge
  95.         V_DEF   LibReserved
  96.  
  97.         V_DEF   _RexxReserved
  98.         V_DEF   _StartService
  99.         V_DEF   _GetServiceAttrsA
  100.  
  101.         DC.L   -1
  102.  
  103. LibDataTable:
  104.         INITBYTE   LN_TYPE,NT_LIBRARY
  105.         INITLONG   LN_NAME,LibName
  106.         INITBYTE   LIB_FLAGS,(LIBF_SUMUSED!LIBF_CHANGED)
  107.         INITWORD   LIB_VERSION,VERSION
  108.         INITWORD   LIB_REVISION,REVISION
  109.         INITLONG   LIB_IDSTRING,LibId
  110.         DC.W       0
  111.  
  112.         CNOP    0,4
  113.  
  114. ;-----------------------------------------------------------------------
  115.  
  116. ; Library Init entry point called when library is first loaded in memory
  117. ; On entry, D0 points to library base, A0 has lib seglist, A6 has SysBase
  118. ; Returns 0 for failure or the library base for success.
  119. LibInit:
  120.         movem.l a0/a5/a6/d7,-(sp)
  121.         move.l  d0,a5
  122.         move.l  d0,_TKSBase
  123.         move.l  a6,TKS_SysBase(a5)
  124.         move.l  a0,TKS_SegList(a5)
  125.  
  126.         move.l  #AO_DOSLib,d7
  127.         lea     DOSName(pc),a1
  128.         bsr.s   OpenLib
  129.         move.l  d0,TKS_DOSBase(a5)
  130.  
  131.         move.l  #AO_UtilityLib,d7
  132.         lea     UtilityName(pc),a1
  133.         bsr.s   OpenLib
  134.         move.l  d0,TKS_UtilityBase(a5)
  135.  
  136.         lea     TKS_OpenLock(a5),a0
  137.         CALL    InitSemaphore
  138.  
  139.         clr.l   TKS_Entity(a5)
  140.         clr.l   TKS_NIPCBase(a5)
  141.  
  142.         move.l  a5,d0
  143.  
  144.         movem.l (sp)+,a0/a5/a6/d7
  145.         rts
  146.  
  147. OpenLib:
  148.         moveq   #LIBVERSION,d0
  149.         CALL    OpenLibrary
  150.         move.l  (sp)+,a0        ; pop return address
  151.         tst.l   d0              ; did lib open?
  152.         beq.s   FailInit        ; nope, so exit
  153.         jmp     (a0)            ; yes, so return
  154.  
  155. FailInit:
  156.         bsr     CloseLibs
  157.         or.l    #AG_OpenLib,d7
  158.         CALL    Alert
  159.         movem.l (sp)+,a0/a5/a6/d7
  160.         moveq   #0,d0
  161.         rts
  162.  
  163. LIBVERSION    EQU  37
  164.  
  165. DOSName         DC.B "dos.library",0
  166. UtilityName     DC.B "utility.library",0
  167. NIPCName        DC.B "nipc.library",0
  168.  
  169.         CNOP    0,4
  170.  
  171. ;-----------------------------------------------------------------------
  172.  
  173. ; Library open entry point called every OpenLibrary()
  174. ; On entry, A6 has ServicesBase, task switching is disabled
  175. ; Returns 0 for failure, or ServicesBase for success.
  176. LibOpen:
  177.         ; see if nipc.library is already open
  178.         tst.l   TKS_NIPCBase(a6)
  179.         bne.s   2$
  180.  
  181.         ; lock anyone else out for a while, since we need to Wait()
  182.         lea.l   TKS_OpenLock(a6),a0
  183.         move.l  a6,-(sp)
  184.         move.l  TKS_SysBase(a6),a6
  185.         CALL    ObtainSemaphore
  186.  
  187.         ; open nipc.library
  188.         lea.l   NIPCName,a1
  189.         clr.l   d0
  190.         CALL    OpenLibrary
  191.         move.l  (sp),a6
  192.         move.l  d0,TKS_NIPCBase(a6)
  193.  
  194.         ; unlock the rest of the word.
  195.         lea.l   TKS_OpenLock(a6),a0
  196.         move.l  TKS_SysBase(a6),a6
  197.         CALL    ReleaseSemaphore
  198.         move.l  (sp)+,a6
  199.  
  200.         ; did nipc open?
  201.         tst.l   TKS_NIPCBase(a6)
  202.         bne.s   2$
  203.         clr.l   d0  ; too bad...
  204.         rts
  205.  
  206.         ; open okay...
  207. 2$      addq.w  #1,LIB_OPENCNT(a6)
  208.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  209.         move.l  a6,d0
  210.         rts
  211.  
  212. ;-----------------------------------------------------------------------
  213.  
  214. ; Library close entry point called every CloseLibrary()
  215. ; On entry, A6 has ServicesBase, task switching is disabled
  216. ; Returns 0 normally, or the library seglist when lib should be expunged
  217. ; due to delayed expunge bit being set
  218. LibClose:
  219.         subq.w  #1,LIB_OPENCNT(a6)
  220.  
  221.         ; if delayed expunge bit set, then try to get rid of the library
  222.         btst    #LIBB_DELEXP,LIB_FLAGS(a6)
  223.         bne.s   CloseExpunge
  224.  
  225.         ; delayed expunge not set, so stick around
  226.         moveq   #0,d0
  227.         rts
  228.  
  229. CloseExpunge:
  230.         ; if no library users, then just remove the library
  231.         tst.w   LIB_OPENCNT(a6)
  232.         beq.s   DoExpunge
  233.  
  234.         ; still some library users, so just flush unused resources
  235.         bclr    #LIBB_DELEXP,LIB_FLAGS(a6)
  236.         moveq   #0,d0
  237.         rts
  238.  
  239. ;-----------------------------------------------------------------------
  240.  
  241. ; Library expunge entry point called whenever system memory is lacking
  242. ; On entry, A6 has ServicesBase, task switching is disabled
  243. ; Returns the library seglist if the library open count is 0, returns 0
  244. ; otherwise and sets the delayed expunge bit.
  245. LibExpunge:
  246.         tst.w   LIB_OPENCNT(a6)
  247.         beq.s   DoExpunge
  248.  
  249.         bset    #LIBB_DELEXP,LIB_FLAGS(a6)
  250.         moveq   #0,d0
  251.         rts
  252.  
  253. DoExpunge:
  254.         movem.l d2/a5/a6,-(sp)
  255.         move.l  a6,a5
  256.         move.l  TKS_SegList(a5),d2
  257.  
  258.         move.l  a5,a1
  259.         REMOVE
  260.  
  261.         move.l  TKS_SysBase(a5),a6
  262.         bsr.s   CloseLibs
  263.  
  264.         move.l  a5,a1
  265.         moveq   #0,d0
  266.         move.w  LIB_NEGSIZE(a5),d0
  267.         sub.l   d0,a1
  268.         add.w   LIB_POSSIZE(a5),d0
  269.         CALL    FreeMem
  270.  
  271.         move.l  d2,d0
  272.         movem.l (sp)+,d2/a5/a6
  273.         rts
  274.  
  275. ;-----------------------------------------------------------------------
  276.  
  277. LibReserved:
  278.         moveq   #0,d0
  279.         rts
  280.  
  281. CloseLibs:
  282.         move.l  TKS_DOSBase(a5),a1
  283.         CALL    CloseLibrary
  284.  
  285.         move.l  TKS_NIPCBase(a5),a1
  286.         CALL    CloseLibrary
  287.  
  288.         move.l  TKS_UtilityBase(a5),a1
  289.         GO      CloseLibrary
  290.  
  291. ;-----------------------------------------------------------------------
  292.  
  293. ; TKSServer Entry Point
  294.  
  295. _TKSServer:
  296.         movea.l _TKSBase(pc),a6
  297.         movea.l _TKSUser(pc),a0
  298.         movea.l _TKSPassword(pc),a1
  299.         movea.l _TKSEntityName(pc),a2
  300.  
  301.         jmp     _Server
  302.  
  303. _TKSBase       DC.L  0
  304. _TKSUser       DC.L  0
  305. _TKSPassword   DC.L  0
  306. _TKSEntityName DC.L  0
  307. _TKSSignalMask DC.L  0
  308. _TKSSMProc     DC.L  0
  309. _TKSError      DC.L  0
  310.  
  311. ;-----------------------------------------------------------------------
  312.  
  313. ; Reserved Function for ARexx.
  314.  
  315. _RexxReserved:
  316.         moveq.l #0,d0
  317.         rts
  318.  
  319. ;-----------------------------------------------------------------------
  320. __sprintf:
  321.         movem.l a2/a3/a4/a6,-(sp)
  322.         move.l  5*4(sp),a3
  323.  
  324.         move.l  6*4(sp),a0
  325.         lea     7*4(sp),a1
  326.         lea     stuffChar(pc),a2
  327.         move.l  TKS_SysBase(a6),a6
  328.         CALL    RawDoFmt
  329.         movem.l (sp)+,a2/a3/a4/a6
  330.         rts
  331.  
  332. stuffChar:
  333.         move.b  d0,(a3)+
  334.         rts
  335.  
  336. ;-----------------------------------------------------------------------
  337.  
  338.         END
  339.